package com.site.controller.manage;

import com.site.model.Banner;
import com.site.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by robin on 2016/12/15.
 * banner controller
 */
@Controller
@RequestMapping("manage/banner")
public class BannerController {
    @Autowired
    private BannerService service;

    @RequestMapping("release")
    public String release(Model model){
        return "manage/banner/release";
    }

    @RequestMapping("main")
    public String main(Model model){
        return "manage/banner/main";
    }

    @RequestMapping("search")
    public String search(Model model,String cate,int pageNum,
                         @RequestParam(defaultValue = "5")int pageSize){
        Banner banner = new Banner();banner.setCate(cate);
        model.addAttribute("data",service.search(banner,pageNum,pageSize));
        return "manage/banner/search";
    }

    @RequestMapping("editPage")
    public String editPage(Model model,String bannerId){
        model.addAttribute("data",service.selectById(bannerId));
        return "manage/banner/edit";
    }

    @RequestMapping("save")
    @ResponseBody
    public int save(Banner banner){
        return service.save(banner);
    }

    @RequestMapping("upSort")
    @ResponseBody
    public int upSort(String id,Integer sort){
        return service.upSort(id,sort);
    }

    @RequestMapping("downSort")
    @ResponseBody
    public int downSort(String id,Integer sort){
        return service.downSort(id,sort);
    }

    @RequestMapping("del")
    @ResponseBody
    public int del(String id){
        return service.delete(id);
    }

    @RequestMapping("edit")
    @ResponseBody
    public int edit(Banner banner){
        return service.edit(banner);
    }
}
